using UnityEngine;
using TMPro;

namespace GameCore
{
    public class AutoInventoryBackground : MonoBehaviour
    {
        
        public Vector2 size;
        
        public Transform mainAreaTransform;
        public Transform imageTransform;
        public Transform dragAreaTransform;
        public BoxCollider2D dragAreaCollider;
        public Transform closeBtnTransform;
        
        public string titleString;
        public RectTransform titleTransform;
        public TMP_Text title;

        private void Start()
        {
            transform.position = new Vector3(-size.x / 2, -size.y / 2, transform.position.z);
            var sr = mainAreaTransform.GetComponent<SpriteRenderer>();
            var c = sr.color;
            c.a = 1;
            sr.color = c;
            
            mainAreaTransform.localPosition = new Vector3(size.x / 2, size.y / 2);
            mainAreaTransform.localScale = new Vector3(size.x + 0.2f, size.y + 0.2f, 1);
            imageTransform.localPosition = new Vector3(size.x / 2, size.y / 2, 0.001f);
            
            dragAreaTransform.localPosition = new Vector3(size.x / 2, size.y + 0.2f, 0);
            dragAreaTransform.localScale = new Vector3(size.x + 0.2f, 0.4f, 1);
            dragAreaCollider.offset = new Vector2(size.x / 2, size.y + 0.3f);
            dragAreaCollider.size = new Vector2(size.x + 0.2f, 0.4f);
            
            titleTransform.localPosition = new Vector3(-0.1f, size.y + 0.2f, -0.001f);
            titleTransform.sizeDelta = new Vector2(size.x + 0.2f, 0.4f);
            title.text = titleString;
            closeBtnTransform.localPosition = new Vector3(size.x, size.y + 0.2f, -0.001f);
        }
    }
}